package org.lewis.demo.controller;

import org.lewis.demo.entity.SysUser;
import org.lewis.demo.service.IUserService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("user")
@RestController
public class UserController {

    private final IUserService userService;

    public UserController(IUserService userService) {
        this.userService = userService;
    }

    @PostMapping("{prefix}/{count}")
    public List<SysUser> init(@PathVariable String prefix, @PathVariable Integer count) {
        return this.userService.init(prefix, count);
    }

    @GetMapping
    public List<SysUser> findAll(@RequestBody SysUser user) {
        return this.userService.findAll(user);
    }

    @GetMapping("{name}")
    public SysUser findByName(@PathVariable String name) {
        return this.userService.findByName(name);
    }

    @DeleteMapping("clean")
    public Long clean() {
        return this.userService.cleanRedis();
    }

}
